var extWindow = null;
var extBody = null;
var mainPanel = null;
var headerPanel = null;
var indexPanel = null;

function onReady(){
	
	initIndexPanel();
	
	initHeaderPanel();
	
	initHeaderButton();
	
	initMainPanel();
	
	initWindowObject();

	initTreePanel();
	
	initTabPanel();
}

Ext.onReady(onReady);
/**
 * 初始化window对象
 * 
 */
function initWindowObject(){
	
	extWindow = Ext.get(window);
	extBody = Ext.getBody();
	
	// 为window注册reszie事件，让mainPanel的尺寸跟随界面大小变化
	extWindow.addListener('resize',function(){
		var width = extBody.getViewSize().width;
		var height = extBody.getViewSize().height;
		
		indexPanel.setWidth(width);
		indexPanel.setHeight(height);
		
		
	});
}
/**
 * 初始化内容区域
 * ID： index_panel
 * 
 */
function initIndexPanel(){
	
	indexPanel = Ext.create('Ext.panel.Panel',{
		id:'index_panel',
		renderTo:Ext.getBody(),
		height:Ext.getBody().getViewSize().height,
		baseCls:'x-plain',
		defaults:{
			frame:true
		},
		layout: {
	        type: 'vbox',
	        align: 'stretch'
		}
	});
	
}
/**
 * 初始化头部面板区域
 * ID: index_header_panel
 */
function initHeaderPanel(){
	
	headerPanel = Ext.create("Ext.panel.Panel",{
		id:'index_header_panel',
		flex:1,
		layout: {
	        type: 'hbox',
	        align: 'stretch'
		},
		baseCls:'x-plain',
		bodyStyle:{
			background:'#d6e2f5',
			padding:'0 0 0 20'
		},
		items:[{
			xtype:'label',
			text:'Xtask Project Manager',
			style:'font-size:25px',	
			padding:'20 0 0 0',
			flex:1
		}]
		
	});
	indexPanel.add(headerPanel);
}
/**
 * 初始化头部按钮
 * ID: index_header_button
 */
function initHeaderButton(){
	
	headerPanel.add(Ext.create('Ext.panel.Panel',{
		id:'index_header_button',
		bodyStyle:{
//			background:'#d6e2f5'
			background:'#ff0'
		},
		border:false,
		layout:{
			type:'hbox',
			align:'stretch'
		},
		padding:5,
		flex:4
	}));
	
	var button1 = $('<div style="width:100px;"><img src="images/icon_button_task.png" style="float:left;" /><span style="float:left;margin:0 0 0 6px;">我的任务</span></div>');
	
	var headerButton = $(Ext.getCmp('index_header_button').getEl().dom);
	
	headerButton.append(button1);
}
/**
 * 初始化主要区域面板
 * ID： index_main_panel
 */
function initMainPanel(){
	
	mainPanel = Ext.create("Ext.panel.Panel",{
		id:'index_main_panel',
		flex:6,
		layout: {
	        type: 'hbox',
	        align: 'stretch'
		},
		baseCls:'x-plain',
		bodyStyle:{
			background:'#d6e2f5'
		}
	});
	indexPanel.add(mainPanel);
}


/**
 * 初始化树形菜单区域
 * 树形菜单区域ID： index_menu_tree_panel
 */
function initTreePanel(){
	
	
	// treeStore
	var treeStore = Ext.create('Ext.data.TreeStore',{
		root:{
			expanded: true,
			children: [{
				text: "已开始任务 (2)", 
				expanded: true, 
				children: [{ 
					text: "[01:36:23] (XMM)完成优秀信息员功能", 
					leaf: true 
				},{ 
					text: "[00:46:11] (XMM)完成热点关注功能", 
					leaf: true
				}] 
			},{
				text: "待完成任务 (2)", 
				expanded: false, 
				children: [{ 
					text: "(XMM)完成益农广播功能", 
					leaf: true 
				},{ 
					text: "(XMM)完成新华连线功能", 
					leaf: true
				}] 
			}]
		}
	});
	
	
	// treePanel
	mainPanel.add(Ext.create('Ext.tree.Panel',{
		id:'index_menu_tree_panel',
		title:'菜单',
		store:treeStore,
		flex:1,
		rootVisible:false
	}));
	
	
}
/**
 * 初始化TabPanel
 * ID： index_tab_panel
 */
function initTabPanel(){
	
	mainPanel.add(Ext.create('Ext.tab.Panel',{
		id:'index_tab_panel',
		flex:4,
		items: [{
	        title: '我的工作面板'
	    }]
	}));
}